<template>
  <div>
    <detailhead :detailhead="singlesDetail" v-if="singlesDetail"></detailhead>
    <!--<z-home></z-home>-->
  </div>
</template>

<script>
import detailhead from '../../component/detail/detailhead.vue'
import {columnService} from '../../service/columnService'
import {appService} from '../../service/appService'
export default {
  components:{'detailhead': detailhead},
  data () {
    return {
      singlesDetail:null
    }
  },
  mounted: function() {
    const that = this;
    // 判断是否登录
    //   if(that.$route.params.type != 1){
    //       if(!appService.checkLogin()) {
    //           that.$router.push({name:'login'})
    //           return
    //       }
    //   }
      columnService.SinglesDetail({id : this.$route.params.id, type :this.$route.params.type || 0 }).then(function (res) {
      if(res.data.datas.code == '0'){ //放行  单品试读和免费
        that.singlesDetail = that.getFormat(res.data.datas.data)
        // console.log(that.singlesDetail,'知识')
      } else if(res.data.datas.code == '1'){ //单品只有一个专栏，直接跳专栏的购买页
          that.$router.replace({name:'column',params:{colId:res.data.datas.data}})
      } else if(res.data.datas.code == '2'){ //一个单品多个专栏
        that.$router.replace({name:'nopay', params:{id:that.$route.params.id}});
      }
              document.title = that.singlesDetail.name

        /*
         * 微信分享设置
         * type查看规则列表写死，
         * text.name为文章标题
         * */
        let params ={
            type:31,
            typeId:that.$route.params.id
        }
        let name = that.singlesDetail.name;
          appService.getWxJssdk().then(function () {
            appService.getWxShare(params,name)
        })
    })
  },
  methods: {
    getFormat: function (array) {
      array.newposter = this.$store.state.picHead + array.poster
      array.newcover = this.$store.state.picHead + array.cover
      return array
    }
  }
}
</script>
<style lang="less">
/*body{
  background: #fff;
}*/
.icon-fanhui{
  color:#fff;
  z-index:20;
}

</style>

